/*  Copyright 2019 Jimmy Hogoboom
 *
 *  This file is part of crumb.
 *
 *  crumb is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  crumb is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with crumb.  If not, see <https://www.gnu.org/licenses/>.
 */

using System;
using NUnit.Framework;

namespace crumb.Api.Core.Domain.Posts
{
    [TestFixture]
    public class PostTests
    {
        private readonly Post _post;
        private readonly Guid Id = Guid.Parse("a8bc7a5a-9ebb-43ae-aafa-8af433b55135");
        private readonly DateTime PostDate = new DateTime(2019, 1, 27);
        private readonly string Title = "Foobar";
        private readonly string Body = "A test body. "; // TODO: Test special characters etc?
        private readonly Guid ParentId = Guid.Parse("4648a1fb-0392-498f-982a-fbcf522f1e44");
        private readonly Guid AccountId = Guid.Parse("fe66f472-f970-43a1-a026-4883f6830993");

        public PostTests()
        {
            _post = new Post(AccountId, Body);
        }

        [Test]
        public void TestConstruction()
        {
            var post = new Post(AccountId, Body);

            Assert.That(post.AccountId,
                Is.EqualTo(AccountId),
                "AccountId is incorrect.");
            Assert.That(post.Body,
                Is.EqualTo(Body),
                "Body is incorrect.");
        }

        [Test]
        public void TestGetAndSet()
        {
            _post.Id = Id;
            _post.PostDate = PostDate;
            _post.Title = Title;
            _post.Body = Body;
            _post.ParentPostId = ParentId;

            Assert.That(_post.Id,
                Is.EqualTo(Id),
                "Id was incorrect.");

            Assert.That(_post.PostDate,
                Is.EqualTo(PostDate),
                "PostDate was incorrect.");

            Assert.That(_post.Title,
                Is.EqualTo(Title),
                "Title was incorrect.");

            Assert.That(_post.Body,
                Is.EqualTo(Body),
                "Body was incorrect.");

            Assert.That(_post.ParentPostId,
                Is.EqualTo(ParentId),
                "ParentPostId was incorrect.");
        }

        [Test]
        public void TestInvalidParentPostId()
        {
            _post.Id = Id;

            Assert.Throws<InvalidOperationException>(
                () => _post.ParentPostId = Id,
                "Setting invalid ParentPostId did not throw.");

            _post.ParentPostId = ParentId;

            Assert.Throws<InvalidOperationException>(
                () => _post.Id = ParentId,
                "Setting invalid Id did not throw.");
        }
    }
}